<?php
// 作物
$file = $_dir.'inc/conf/item/crop.cfg.php';
if (!is_file($file)) {
	echo $file.' is not exists!';
	exit;
}
$arr = include $file;
// 水果
$file = $_dir.'inc/conf/item/fruit.cfg.php';
if (!is_file($file)) {
	echo $file.' is not exists!';
	exit;
}
$tmp = include $file;
$arr = $arr + $tmp;
// 动物
$file = $_dir.'inc/conf/item/animal.cfg.php';
if (!is_file($file)) {
	echo $file.' is not exists!';
	exit;
}
$tmp = include $file;
$arr = $arr + $tmp;
foreach ($tmp as $v) {
	$arr[$v['product_id']] = array(
		'title' => $v['product_title'],
		'item_type' => $v['product_item_type'],
		'lvl'	=> $v['lvl'],
		'price'	=> $v['product_price']
	);
}
// 采集
$file = $_dir.'inc/conf/item/gather.cfg.php';
if (!is_file($file)) {
	echo $file.' is not exists!';
	exit;
}
$tmp = include $file;
$arr = $arr + $tmp;
// 宝箱
$file = $_dir.'inc/conf/item/treasure_box.cfg.php';
if (!is_file($file)) {
	echo $file.' is not exists!';
	exit;
}
$tmp = include $file;
$arr = $arr + $tmp;
// 宝石
$file = $_dir.'inc/conf/item/gem.cfg.php';
if (!is_file($file)) {
	echo $file.' is not exists!';
	exit;
}
$tmp = include $file;
$arr = $arr + $tmp;
// 装备
$file = $_dir.'inc/conf/item/equip.cfg.php';
if (!is_file($file)) {
	echo $file.' is not exists!';
	exit;
}
$tmp = include $file;
$arr = $arr + $tmp;
// 礼物
$file = $_dir.'inc/conf/item/gift.cfg.php';
if (!is_file($file)) {
	echo $file.' is not exists!';
	exit;
}
$tmp = include $file;
$arr = $arr + $tmp;
// 金钱等
$file = $_dir.'inc/conf/item/other.cfg.php';
if (!is_file($file)) {
	echo $file.' is not exists!';
	exit;
}
$tmp = include $file;
$arr = $arr + $tmp;

C('build/making');

// 辅材
$sec_mat_type_list = array(
	'cook', 'drink', 'furniture'
);
include($_dir.'inc/conf/build/making.cfg.php');
foreach ($sec_mat_type_list as $v) {
	$arr = $arr + $GLOBALS['G'][$v.'_sec_mat_item'];
}

// 化肥
$file = $_dir.'inc/conf/item/fertiliser.cfg.php';
if (!is_file($file)) {
	echo $file.' is not exists!';
	exit;
}
$tmp = include $file;
$arr = $arr + $tmp;

// 营养剂
$file = $_dir.'inc/conf/item/nutrient.cfg.php';
if (!is_file($file)) {
	echo $file.' is not exists!';
	exit;
}
$tmp = include $file;
$arr = $arr + $tmp;

$itemList = array();
$itemNameIdList = array();
$seedList = array();
$secMatList = array();

// 制造的产品
foreach ($G['make_class_list'] as $sign => $name) {
	$list = $G[$sign];
	foreach ($list as $v) {
		$itemList[$v['item_id']] = array(
			'title' => $v['title'],
			'type'  => $v['item_type'],
			'lvl'	=> 0
		);
	}
}


foreach ($arr as $k=>$v) {
	if (!isset($v['lvl'])) {
		$v['lvl'] = 0;
	}
	if (isset($v['price'])) {
		$itemList[$k] = array(
			'title' => $v['title'],
			'type'  => $v['item_type'],
			'lvl'	=> $v['lvl'],
			'price'	=> $v['price']
		);
	} elseif (isset($v['price_list'])) {
		$itemList[$k] = array(
			'title' => $v['title'],
			'type'  => $v['item_type'],
			'lvl'	=> $v['lvl'],
			'price'	=> $v['price_list']
		);
	} else {
		$itemList[$k] = array(
			'title' => $v['title'],
			'type'  => $v['item_type'],
			'lvl'	=> $v['lvl']
		);
	}
	$itemNameIdList[$v['title']] = $k;
	if (isset($v['product_id'])) {
		$itemList[$k]['product_id'] = $v['product_id'];
	}
	//是否有种子
	if (isset($v['seed_id'])) {
		$itemList[$v['seed_id']] = array(
			'title' => $v['seed_title'],
			'type'  => $v['seed_item_type'],
			'lvl'	=> $v['lvl'],
			'price' => $v['seed_price']
		);
		$seedList[$v['seed_id']] = $k;
		$itemNameIdList[$v['seed_title']] = $v['seed_id'];
	}
	//是否辅材
	if ($v['item_type'] == 51) {
		$secMatList[$k] = array(
			'title' => $v['title'],
			'item_type'  => $v['item_type'],
			'lvl'	=> $v['lvl']
		);
	}
}

// 所有物品列表
ksort($itemList);
$str = 'return '.var_export($itemList, true);
$filename = $_dir.'inc/conf/item/item_list.cfg.php';
writefile($filename, $str, 'php');
// 物品名称对应ID
asort($itemNameIdList);
$str = 'return '.var_export($itemNameIdList, true);
$filename = $_dir.'inc/conf/item/item_name_id_list.cfg.php';
writefile($filename, $str, 'php');

// 辅材列表
ksort($secMatList);
$str = 'return '.var_export($secMatList, true);
$filename = $_dir.'inc/conf/item/sec_mat_list.cfg.php';
writefile($filename, $str, 'php');


// 种子列表（对应产品的ID）
ksort($seedList);
$str = 'return '.var_export($seedList, true);
$filename = $_dir.'inc/conf/item/seed_list.cfg.php';
writefile($filename, $str, 'php');

echo $filename;

